﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Maticsoft.DBUtility;
using WebManager;

namespace BaoJian.WebManager.Manager.VIP
{
    public partial class New : System.Web.UI.Page
    {
        string selRegion = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LYQ.BLL.S_Group bll = new LYQ.BLL.S_Group();
                if (Utility.CurrentSysUser().UName.ToLower() != "admin")
                {
                    Region.DataSource = bll.GetList("GID ='" + Utility.CurrentSysUser().GID + "'").Tables[0];
                }
                else
                {
                    Region.DataSource = bll.GetList("GID !='19800628-1111-0000-0000-000000000001'");
                }
                Region.DataTextField = "GName";
                Region.DataValueField = "GID";
                Region.DataBind();
                selRegion = Region.SelectedItem.Text;
                txtFlashPath.Text += @"\" + selRegion + @"\";            
            }
        }

        protected void Save_Click(object sender, EventArgs e)
        {          

            string strErr = "";
           
            if (this.txtName.Text == "")
            {
                strErr += "Name不能为空！\\n";
            }
            if (this.txtTel.Text == "")
            {
                strErr += "Tel不能为空！\\n";
            }
            if (this.txtAddress.Text == "")
            {
                strErr += "Address不能为空！\\n";
            }
            //if (this.txtQQ.Text == "")
            //{
            //    strErr += "QQ不能为空！\\n";
            //}
            //if (this.txtMobile.Text == "")
            //{
            //    strErr += "Mobile不能为空！\\n";
            //}
            if (this.txtFlashPath.Text == "")
            {
                strErr += "FlashPath不能为空！\\n";
            }
            if (this.txtIntroduce.Text == "")
            {
                strErr += "Introduce不能为空！\\n";
            }
            if (this.txtProductWhere.Text == "")
            {
                strErr += "ProductWhere不能为空！\\n";
            }
            if (this.txtPageKeyWord.Text == "")
            {
                strErr += "PageKeyWord不能为空！\\n";
            }

            //if (strErr != "")
            //{
            //    MessageBox.Show(this, strErr);
            //    return;
            //}
            int SID = DbHelperSQL.GetMaxID("SID", "VIPPartner");
            string Name = this.txtName.Text;
            string Tel = this.txtTel.Text;
            string Address = this.txtAddress.Text;
            string QQ = this.txtQQ.Text;
            string Mobile = this.txtMobile.Text;
            string FlashPath = this.txtFlashPath.Text;
            string Introduce = this.txtIntroduce.Text;
            string ProductWhere = this.txtProductWhere.Text;
            string PageKeyWord = this.txtPageKeyWord.Text;

            LYQ.Model.VIPPartner model = new LYQ.Model.VIPPartner();
            model.SID = SID;
            model.Region = Region.SelectedItem.Text;
            model.OID = Guid.NewGuid().ToString();
            model.Name = Name;
            model.Tel = Tel;
            model.Address = Address;
            model.QQ = QQ;
            model.Mobile = Mobile;
            model.FlashPath = FlashPath;
            model.Introduce = Introduce;
            model.ProductWhere = ProductWhere;
            model.PageKeyWord = PageKeyWord;       
            model.Inside = chkInside.Checked; 
            if(chkInside.Checked)
            {
                model.URL ="/vip/intro.aspx?vid="+model.OID;
            }
            else
            {
                model.URL = txtURL.Text;
            }

            LYQ.BLL.VIPPartner bll = new LYQ.BLL.VIPPartner();
            bll.Add(model);
            string url = URLUtility.UrlBase + @"/WebManager/manager/vip/List.aspx";
            Page.Response.Redirect(url);
        }

        protected void Cancel_Click(object sender, EventArgs e)
        {
            string url = URLUtility.UrlBase + @"/WebManager/manager/vip/List.aspx";
            Page.Response.Redirect(url);
        }

        protected void Region_SelectedIndexChanged(object sender, EventArgs e)
        {
            selRegion = Region.SelectedItem.Text;
            txtFlashPath.Text = @"\uploads\vippartner\" + selRegion;
        }
    }
}
